package cn.mugutu.finance.controller;

import cn.mugutu.finance.annotation.SysResource;
import cn.mugutu.finance.domain.system.Log;
import cn.mugutu.finance.dto.BaseResult;
import cn.mugutu.finance.dto.BaseResult.EasyUIResult;
import cn.mugutu.finance.query.LogQuery;
import cn.mugutu.finance.service.system.LogService;
import cn.mugutu.finance.utils.Pager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/log")
public class LogController extends BaseController {

    @Autowired
    private LogService logService;

    @RequestMapping("/listUI")
    @SysResource(name = "系统日志管理页面", code = "log:listui")
    public String listUI() {
        return "log/list";
    }

    @RequestMapping("/list")
    @ResponseBody
    @SysResource(name = "查询日志数据", code = "log:list")
    public EasyUIResult<Log> list(LogQuery query, int page, int rows) {
        setEasyUIParamsInQuery(query, page, rows);
        Pager<Log> pager = logService.findByPage(query);
        return new EasyUIResult<Log>(pager.getTotalCount(), pager.getRows());
    }

    @ResponseBody
    @RequestMapping("/delete")
    @SysResource(name = "删除日志", code = "log:delete")
    public BaseResult delete(Long id) {
        logService.delete(id);
        return new BaseResult(true, "删除成功");
    }

    @ResponseBody
    @RequestMapping("/deleteAll")
    @SysResource(name = "清空系统日志", code = "log:deleteall")
    public BaseResult deleteAll() {
        logService.deleteAll();
        return new BaseResult(true, "清空系统日志成功");
    }

}
